import {
	baseUrl
} from '@/utils/request.js'

let single = '/api/commons/upload'
let multiple = '/api/commons/uploads'


export const uploadFileFn = (params) => {
	uni.showLoading({
		title: ''
	})
	// const type = Object.prototype.toString.call(params);
	// '[object File]' '[object Object]' '[object Array]'
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			header: {
				"known-session": uni.getStorageSync('token')
			},
			url: baseUrl + single,
			name: params.name ? params.name : 'file',
			filePath: params.path,
			formData: {
				user: 'test'
			},
			timeout: 1000 * 6,
			success: (res) => {
				resolve(res.data)
			},
			fail: (err) => {
				reject(err)
			},
			complete: (end) => {
				uni.hideLoading()
			}
		})
	})
}
